package com.fwtai.service.api;

import com.fwtai.api.ApiOrderDao;
import com.fwtai.bean.PageFormData;
import com.fwtai.config.LocalUserId;
import com.fwtai.tool.ToolClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 资料文档相关
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2021-08-10 11:19:15
 * @官网 <url>http://www.fwtai.com</url>
*/
@Service
public class ApiOrderService{

    @Resource
    private ApiOrderDao apiOrderDao;

    public String getListOrder(final HttpServletRequest request){
        final String loginId = LocalUserId.get();
        if(loginId == null){
            return ToolClient.accessLogin();
        }
        final PageFormData formData = ToolClient.pageParamsApi(request);
        if(formData == null) return ToolClient.jsonValidateField();
        final Integer type = formData.getInteger("type");
        if(type == null){
            return ToolClient.jsonValidateField();
        }
        formData.remove("type");
        switch (type){//0为全部类型;1未付款;2已付款;3待评价;4已评价;5未退款;6已退款;（评价是对律师评价还是对某个案件还是某个服务评价?）
            case 1:
                formData.put("type",0);
                break;
            case 2:
                formData.put("type",1);
                break;
            case 3:
                //todo 其他类型的处理1,评价得新建表
                formData.put("evaluate",0);
                formData.put("type",1);
                break;
            case 4:
                formData.put("evaluate",1);
                formData.put("type",1);
                //todo 其他类型的处理2,'退款'得新建表
                break;
            case 5:
                formData.put("refund",0);
                formData.put("type",1);
                break;
            case 6:
                formData.put("refund",1);
                formData.put("type",1);
                break;
            default:
                break;
        }
        formData.put("loginId",loginId);
        return ToolClient.jsonPage(apiOrderDao.getListOrder(formData));
    }

    public String delById(final String kid){
        final String loginId = LocalUserId.get();
        if(loginId == null){
            return ToolClient.accessLogin();
        }
        final PageFormData formData = new PageFormData();
        formData.put("loginId",loginId);
        formData.put("kid",kid);
        return ToolClient.executeRows(apiOrderDao.delById(formData));
    }
}